package com.easyarlibrary.artools.ar;

import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;

import com.easyarlibrary.app.BaseAppConstant;
import com.easyarlibrary.util.LoadTargetUtil;
import com.easyarlibrary.util.LogUtil;

import cn.easyar.ImageTracker;
import cn.easyar.TargetInstance;

/**
 * createTime：2019/2/25/025 on 17:04
 *
 * @author: jyc dell
 */
public class CoverAR extends BaseAR {
    private String currName;
    private Handler handler;

    public CoverAR(Handler handler) {
        this.handler = handler;
    }

    @Override
    protected void initData(ImageTracker tracker) {
        LoadTargetUtil.loadAllFromAssetsJsonFile(tracker, "targets.json", 1);
    }

    public void reSetCurrName() {
        currName = "";
    }

    @Override
    protected void doResule(TargetInstance targetInstance) {
        String currTempName = targetInstance.target().name();
        if (!TextUtils.isEmpty(currName) && currName.equals(currTempName)) {
            return;
        }
        LogUtil.d("----识别结果----->" + targetInstance.target().name());
        currName = currTempName;
        Message msg = new Message();
        msg.obj = currName;
        msg.what = BaseAppConstant.HanlderWhat.HANDLE_WHAT_GETBOOKNAME_OK;
        //延迟200ms发送防止识别有误
        handler.sendMessageDelayed(msg, 200);

    }
}
